from django.db import models
from django.contrib.auth.models import User

class AddressBook(models.Model):
    full_name = models.CharField(max_length=120)
    mobile_number = models.CharField(max_length=60, unique=True)
    history = models.TextField(blank=True)
    class Meta:
        db_table = 'addressbook'
        verbose_name_plural = 'Address Book'
    def __unicode__(self):
        return self.full_name

# gnokii-smsd models. Prospected from MySQL schema
class Inbox(models.Model):
    id = models.IntegerField(primary_key=True)
    number = models.CharField(max_length=60)
    smsdate = models.DateTimeField()
    insertdate = models.DateTimeField()
    text = models.TextField(blank=True)
    phone = models.IntegerField(null=True, blank=True)
    processed = models.IntegerField()
    class Meta:
        db_table = u'inbox'
        verbose_name_plural = 'Inbox'
    def __unicode__(self):
        return self.number

class Multipartinbox(models.Model):
    number = models.CharField(max_length=60)
    smsdate = models.DateTimeField()
    insertdate = models.DateTimeField()
    text = models.TextField(blank=True)
    phone = models.IntegerField(null=True, blank=True)
    processed = models.IntegerField()
    refnum = models.IntegerField(null=True, blank=True)
    maxnum = models.IntegerField(null=True, blank=True)
    curnum = models.IntegerField(null=True, blank=True)
    class Meta:
        db_table = u'multipartinbox'
        verbose_name_plural = 'Multipart Inbox'
    def __unicode__(self):
        return self.number

class Outbox(models.Model):
    number = models.ForeignKey(AddressBook, to_field='mobile_number')
    processed_date = models.DateTimeField(blank=True, null=True)
    insertdate = models.DateTimeField(auto_now_add=True)
    text = models.TextField(max_length=160)
    sent_by = models.ForeignKey(User)
    phone = models.IntegerField(null=True, blank=True)
    processed = models.IntegerField(blank=True, null=True)
    error = models.IntegerField(blank=True, null=True)
    dreport = models.IntegerField(blank=True, null=True)
    not_before = models.CharField(max_length=8, blank=True) # time in format 00:00:00
    not_after = models.CharField(max_length=8, blank=True) # time in format 00:00:00
    class Meta:
        db_table = u'outbox'
        verbose_name_plural = 'Outbox'
    def __unicode__(self):
        return u'%s %s' % (self.sent_by, self.number)
